/*
 *  Copyright (C) 2011 glauco
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.swing.components.panel.layouts;

import java.util.Map;
import javax.swing.GroupLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle;
import org.balisunrise.swing.components.panel.LayoutBuilder;


/**
 *
 * @author glauco
 */
public class MessengerLayoutBuilder implements LayoutBuilder{

    private Map<String,JLabel> messages;
    
    private JLabel lbMode;

    public JLabel getLbMode() {
        return lbMode;
    }

    public void setLbMode(JLabel lbMode) {
        this.lbMode = lbMode;
    }

    public Map<String, JLabel> getMessages() {
        return messages;
    }

    public void setMessages(Map<String, JLabel> messages) {
        this.messages = messages;
    }
    
    @Override
    public void buildLayout(JPanel panel) {
        panel.removeAll();
        GroupLayout layout = new GroupLayout(panel);
        panel.setLayout(layout);

        // HORIZONTAL
        GroupLayout.ParallelGroup hGroup =
                layout.createParallelGroup(GroupLayout.Alignment.LEADING, true);

        // VERTICAL
        GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();

        hGroup.addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(lbMode)
                    .addContainerGap());

        vGroup.addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbMode)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED));

        for (JLabel msg : messages.values()) {
            hGroup.addComponent(msg);
            vGroup.addComponent(msg);
        }
        
        //vGroup.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
        vGroup.addContainerGap();

        layout.setHorizontalGroup(layout.createSequentialGroup()
                .addGroup(hGroup));

        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
            .addGroup(vGroup));
    }



}
